package com.wind.taobao.api.trade.product.convert
{
	import com.wind.taobao.api.trade.product.model.ProductPropImg;
	import com.wind.taobao.core.util.TaobaoConstants;

	import mx.collections.ArrayCollection;

	/**
	 * ProductPropImg 转换器
	 * @author fxy
	 *
	 */
	public class ProductPropImgConvert
	{
		/**
		 * 转换ProductPropImg集合
		 */
		public static function convertProductPropImgs(value:Object, type:String="json"):ArrayCollection
		{
			var productPropImgs:ArrayCollection=new ArrayCollection();
			if (value != null)
			{
				if (type == TaobaoConstants.JSON)
				{
					if ((value as Array).length > 0)
					{
						for (var i:uint=0; i < (value as Array).length; i++)
						{
							productPropImgs.addItem(convertProductPropImg((value as Array)[i]));
						}
					}
				}
				else
				{
					//TODO
				}
			}
			return productPropImgs;
		}

		/**
		 * 转换ProductPropImg
		 */
		public static function convertProductPropImg(value:Object, type:String="json"):ProductPropImg
		{
			var productPropImg:ProductPropImg=new ProductPropImg();
			if (value == null)
				return productPropImg;
			if (type == TaobaoConstants.XML)
			{
				productPropImg=convertXMLToProductPropImg(XML(value), productPropImg);
			}
			else
			{
				productPropImg=convertJSONToProductPropImg(value, productPropImg);
			}
			return productPropImg;
		}

		/**
		 * JSON转换为ProductPropImg
		 */
		private static function convertJSONToProductPropImg(json:Object, productPropImg:ProductPropImg):ProductPropImg
		{
			if (json.hasOwnProperty(TaobaoConstants.PICID))
			{
				productPropImg.pic_id=json[TaobaoConstants.PICID];
			}
			if (json.hasOwnProperty(TaobaoConstants.PRODUCT_ID))
			{
				productPropImg.product_id=json[TaobaoConstants.PRODUCT_ID];
			}
			if (json.hasOwnProperty(TaobaoConstants.URL))
			{
				productPropImg.url=json[TaobaoConstants.URL];
			}
			if (json.hasOwnProperty(TaobaoConstants.POSITION))
			{
				productPropImg.position=json[TaobaoConstants.POSITION];
			}
			if (json.hasOwnProperty(TaobaoConstants.PROPS))
			{
				productPropImg.props=json[TaobaoConstants.PROPS];
			}
			return productPropImg;
		}

		/**
		 * XML转换为ProductPropImg
		 */
		private static function convertXMLToProductPropImg(value:XML, productPropImg:ProductPropImg):ProductPropImg
		{
			return productPropImg;
		}
	}
}